<?php include "../../../config.php";?>
<?php include ROOT_PATH_."/front/m2/coresection/checkUserSession.php";?>
<?$userinfo = select_one_line_all_items($table_Prefix."user","mid = '".$user_mid."'"); ?>


<?


$menu = array();

for($i=0;$i<count($_REQUEST['ai_product_num']);$i++)
{
    for($ii=0;$ii<$_REQUEST['ai_product_num'][$i];$ii++)
    {
		$menu[] = $_REQUEST['ai_product_id'][$i];
        $value[]=array(
            $_REQUEST['ai_product_name'][$i],
            $_REQUEST['ai_product_id'][$i],
            $_REQUEST['ai_product_price'][$i],
            $_REQUEST['ai_order_date'][$i],
            '1',
            $userinfo['mid'],
            $userinfo['name'],
            date("Y-m-d H:i:s"),
            $_REQUEST['ai_order_at'][$i],
            date("Ym")
        )


        ;

    }
}

if($menu){
	
	$search_id = "'".implode("','",$menu)."'";
	
	$order_list = select_lines_all_items   ($tabel_prefix."athlon_orderlist","nid asc ","product_id IN ($search_id) AND status is NULL AND user_id =".$user_mid); //菜单
	
	if($order_list){
		echo '<script>alert("订单状态有误，已取消，请刷新后再操作");window.location.href="../order-list.php";</script>'; 
		exit;
	}
	
	$product_id_list = array();
	foreach($order_list as $val){
		if($product_id_list[$val['product_id']]){
			$product_id_list[$val['product_id']]++;
		}
		else{
			$product_id_list[$val['product_id']] = 1;
		}
	}
	
	
}

$data['items']  =array(
"product_name",
"product_id",
"product_price",
"order_date",
"product_num",

"user_id",
"user_name",
"ondate",
"order_at",
"search_key"
);





$data['values'] =$value;
$data['table']  =$table_Prefix."orderlist";


 $insert_order_sql=insert_datas($data);

$query = mysql_query($insert_order_sql) or die ("error:".mysql_error());

?>

<script type="text/javascript">
    alert("订餐成功！");
    document.location = "../order-list.php";
</script>



?>